{% extends "base.html" %}

{% block title %} Book List{% endblock %}

{% load humanize %}
{% block content %}
    {% if metabooks.object_list %}
        {% if metabooks.has_other_pages %}
            <div class="PageCounterNav">
                <p>
                {% if metabooks.has_previous %}
                    <a href="?page={{ metabooks.previous_page_number }}&amp;per_page={{ per_page }}">
                        <img src="{{ MEDIA_URL }}images/pagenav_prev.gif" alt="Previous Page" />
                    </a>
                {% else %}
                    <img src="{{ MEDIA_URL }}images/pagenav_prev_faded.gif" alt="No Previous Page" />
                {% endif %}
                Pages: ({{ metabooks.number }} of {{ books.paginator.num_pages }})
                {% if metabooks.has_next %}
                    <a href="?page={{ metabooks.next_page_number }}&amp;per_page={{ per_page }}">
                        <img src="{{ MEDIA_URL }}images/pagenav_next.gif" alt="Next Page" />
                    </a>
                {% else %}
                    <img src="{{ MEDIA_URL }}images/pagenav_next_faded.gif" alt="No Next Page" />
                {% endif %}
            </div>
        {% endif %}
        <form action="{% url update_metabooks %}" method="post" name="ListItems">
        <table cellspacing='0'>
            <thead>
                <tr>
                    <th>
                        <a href="javascript:void(0);" onclick="toggleCBTogether();">All</a>
                    </th>
                    <th>
                        <a href="{{ cube.books.views.list }}?page={{ page }}&amp;per_page={{ per_page }}&amp;sort_by=author&amp;dir={{ dir }}">Author</a>
                    </th>
                    <th>
                        <a href="{{ cube.books.views.list }}?page={{ page }}&amp;per_page={{ per_page }}&amp;sort_by=title&amp;dir={{ dir }}">Title</a>
                    </th>
                    <th>
                        <a href="{{ cube.books.views.list }}?page={{ page }}&amp;per_page={{ per_page }}&amp;sort_by=courses&amp;dir={{ dir }}">Courses</a>
                    </th>
                    {% if user.is_staff %}
                    <th>
                        <a href="{{ cube.books.views.list }}?page={{ page }}&amp;per_page={{ per_page }}&amp;sort_by=barcode&amp;dir={{ dir }}">Barcode</a>
                    </th>
                    {% endif %}
                </tr>
            </thead>
            <tbody>
            {% for metabook in metabooks.object_list %}
                <tr class="{% cycle 'bgcolor_odd' 'bgcolor_even' %}">
                    <td class='row_check'>
                        <input type='checkbox' name="idToEdit{{ forloop.counter }}" value="{{ metabook.id }}" />
                    </td>
                    <td>{{ metabook.author }}</td>
                    <td>
                        {{ metabook.title }}
                        {% ifnotequal metabook.edition 1 %}
                            ({{ metabook.edition|ordinal }} ed.)
                        {% endifnotequal %}
                    </td>
                    <td>{{ metabook.course_codes }}</td>
                    <td>{{ metabook.barcode }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        <p class="submit_options">
            <input type="submit" name="Action" value="Edit" />
        </p>
        </form>
    {% endif %}
{% endblock %}
